use chrono::{DateTime, Utc};
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
use uuid::Uuid;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "resources")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub id: Uuid,
    pub file_name: String,
    pub extension: String,
    pub url: String,
    pub file_size: i64,
    pub mime_type: String,
    pub created_at: DateTime<Utc>,
    pub updated_at: DateTime<Utc>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
    #[sea_orm(has_many = "super::article_resource::Entity")]
    ArticleResource,
    #[sea_orm(has_many = "super::product_resource::Entity")]
    ProductResource,
}

impl Related<super::article_resource::Entity> for Entity {
    fn to() -> RelationDef {
        Relation::ArticleResource.def()
    }
}

impl Related<super::product_resource::Entity> for Entity {
    fn to() -> RelationDef {
        Relation::ProductResource.def()
    }
}

impl ActiveModelBehavior for ActiveModel {}